package com.tiantianyuegou.adapter;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.trouble.framework.adapter.BaseAdapterHelper;
import com.trouble.framework.adapter.QuickAdapter;
import com.tiantianyuegou.R;
import com.tiantianyuegou.model.ColorOrSizeModel;

import java.util.List;

/**
 * 添加购物车或立即购买界面的gird的adaper
 * Created by ivany on 2016/1/12.
 */
public class ColorOrSizeGridAdapter extends QuickAdapter<ColorOrSizeModel> {

    private Context mContext;

    public ColorOrSizeGridAdapter(Context context, List<ColorOrSizeModel> items) {
        super(context, R.layout.grid_item_selector_modular);
        data.addAll(items);
        mContext = context;
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    @Override
    protected void convert(BaseAdapterHelper baseAdapterHelper, ColorOrSizeModel colorOrSizeItem) {
        LinearLayout linear = baseAdapterHelper.getView(R.id.selector_item_linear);
        TextView lable = baseAdapterHelper.getView(R.id.selector_item_content);
        lable.setText(colorOrSizeItem.label);
        boolean isSelect = colorOrSizeItem.isSelect;
        if (isSelect) {
            lable.setTextColor(mContext.getResources().getColor(R.color.textcolor_red));
            linear.setBackground(mContext.getResources().getDrawable(R.drawable.background_selector));
        } else {
            lable.setTextColor(mContext.getResources().getColor(R.color.textcolor_gray));
            linear.setBackground(mContext.getResources().getDrawable(R.drawable.background_unselector));
        }
    }

}
